#!/bin/sh
php /var/www/html/docker/env_replace.php

# shellcheck disable=SC2039
if [[ ! -e "/var/www/html/vendor" ]]; then
    composer install
fi

# shellcheck disable=SC2039
if [[ -e "/var/www/html/supervisor/" ]]; then
    if ! command -v supervisord >/dev/null 2>&1; then
        sed -i 's|https://dl-cdn.alpinelinux.org/alpine/v3.19|https://mirrors.aliyun.com/alpine/v3.19|' /etc/apk/repositories
        apk update
        apk add supervisor
    fi
    echo_supervisord_conf > /etc/supervisord.conf
    /usr/bin/supervisord -c /etc/supervisord.conf
fi

# shellcheck disable=SC2039
if [[ -e "/var/www/html/supervisor/" ]]; then
    for file in /var/www/html/supervisor/*; do
        if [ -f "$file" ]; then
            cat "$file" >> "/etc/supervisord.conf"
        fi
    done
    supervisorctl reload
fi
